import java.util.ArrayList;
import java.util.Random;

public class test {
    public static void main(String[] args) {
        System.out.println(getCode());
    }

    public static String getCode() {
        //创建集合添加元素
        ArrayList<Character> list = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            list.add((char) ('a' + i));
            list.add((char) ('A' + i));
        }

        //创建随机变量
        StringBuilder sb = new StringBuilder();
        Random r = new Random();
        for (int i = 0; i < 4; i++) {
            int index = r.nextInt(list.size());
            char c = list.get(index);
            sb.append(c);
        }

        //添加一个随机数到末尾
        int number = r.nextInt(10);//范围0到9
        sb.append(number);

        //修改字符串中的内容要将其转换成字符数组在进行修改
        char arr[] = sb.toString().toCharArray();
        //拿着最大的索引进行一个交换
        int randomindex = r.nextInt(arr.length);
        char temp = arr[randomindex];
        arr[randomindex] = arr[arr.length - 1];
        arr[arr.length - 1] = temp;
        return new String(arr);
    }

}
